package router

import (
	"go-web/api"
	"net/http"
	"go-web/web"
)

type Router struct {
	Mux *http.ServeMux
}

var routerMap map[string] http.HandlerFunc

func init()  {
	//注册拦截器
	web.Register("/book/*", web.UserFilter)

	//注册正常的路由
	routerMap = make(map[string] http.HandlerFunc)
	routerMap["/"] = web.Handle(api.IndexHandle())
	routerMap["/user"] = web.Handle(api.UserHandle())
	routerMap["/msg"] = web.Handle(api.MsgHandler())
	routerMap["/blog"] = web.Handle(api.BlogHandler())
	routerMap["/book"] = web.Handle(api.BookHandler())
	routerMap["/check"] = web.Handle(api.CheckHandler())
}

func (router *Router) HandleRouter()  {
	mux := router.Mux
	for k,v := range routerMap{
		mux.HandleFunc(k, v)
	}
}
